import java.util.Arrays;

import static java.util.Arrays.copyOfRange;

public class 课堂练习 {
    public static void main(String[] args) {
        int[][] arr = {{1,2,3},{4,5,6}};
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 3; j++) {
                System.out.println(arr[i][j] + " ");
            }
        }
    }

    public static boolean line(int[] add) {
        int count = 0;
        for (int i = 0; i < add.length; i++) {
            if (add[i] % 2 == 0) {
                count++;
                if (count == 3) {
                    return true;
                }
            }else {
                count = 0;
            }
        }
        return false;
    }
    public static int singleNum(int[] add) {
        int ret = 0;
        for (int i = 0; i < add.length; i++) {
            ret ^= add[i];//异或符号 相同就等于0；
        }
        return ret;
    }
    public static int[] add(int[] add, int i) {
        int[] tep = {-1,-1};
        for (int a = 0; a < add.length; a++) {
            for (int b = a + 1; b < add.length - 1; b++) {
                if (add[a] + add[b] == i) {
                    tep[0] = a;
                    tep[1] = b;
                }
            }
        }
        return tep;

    }
    public static void main6(String[] args) {
        int[] arr = {2,7,11,13};
        int[] arr2 = {1,2,1,2,3};
        int[] arr3 = {2,1,3,5,44,51,7,23};
       int[] k = add(arr, 18);
       int a = singleNum(arr2);
       boolean as = line(arr3);
        System.out.println(as);
        //System.out.println(Arrays.toString(k));
        //System.out.println(a);
    }
    public static void svip(int[] arr) {
        //奇数在偶数前
        int i = 0;
        int j = arr.length - 1;
        while (i < j) {
            while (i < j && arr[i] % 2 != 0) {
                i++;
            }
            while (i < j && arr[j] % 2 == 0) {
                j--;
            }
            int ten = arr[i];
            arr[i] = arr[j];
            arr[j] = ten;
        }
    }
    public static void twise(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            arr[i] *= 2;
        }
    }
    public static void bubbleSout(int[] arr) {
        //int i = 0;
        for (int i = 0; i < arr.length; i++) {
            //走多少趟
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    //交换
                    int tem = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = tem;

                }

            }
        }

    }
    public static void main5(String[] args) {
        //冒泡排序
        int[] arr = {1,22,3,4,32};
        //bubbleSout(arr);

        //Arrays.sort(arr);//自带的排序
        //System.out.println(Arrays.toString(arr));
        //twise(arr);
        svip(arr);
        System.out.println(Arrays.toString(arr));

    }
    public static int halfsolt(int[] arr, int i) {
        int left = 0;
        int right = arr.length - 1;
        while (left < right) {
            int mid = (left + right) / 2;
            if (arr[mid] < i) {
                left = mid + 1;
            }else if (arr[mid] == i) {
                return mid;
            }else {
                right = mid - 1;
            }
        }
        return -1;
    }
   //return -1;
    public static void main4(String[] args) {
        //二分查找
        int[] arrey = {1,2,3,4,5};
        int i = halfsolt(arrey, 3);
        if (i != -1) {
            System.out.println(i);
        }
    }
    public static int find(int[] arr, int i) {
        for (int j = 0; j < arr.length; j++) {
            if (arr[j] == i) {
                return j;
             }
            }
        return -1;

    }
    public static void main3(String[] args) {
        int[] arrey = {1,2,3,4,5};
        int i = find(arrey, 3);
        if (i != -1) {
            System.out.println("下标是：" + i);
        }

        //方法 顺序查找

    }
    public static void main2(String[] args) {
        //扩容
        int[] arrey = {1,2,3,4,5};
       // int[] copy = Arrays.copyOf(arrey, arrey.length * 2);//扩容用0补充
        //arrey = copy;
        int[] copy = copyOfRange(arrey, 1,3);//区间取值是左闭右开
        //
       // System.out.println();
        System.out.println(Arrays.toString(copy));//格式化输出

    }
    public static void main1(String[] args) {
        //拷贝
        int[] arrey = {1,2,3,4,5};
        //int[] copy = new int[arrey.length];
        int[] copy = Arrays.copyOf(arrey,arrey.length);//想要拷贝的数组名字和数组长度
        //for (int i = 0; i < arrey.length; i++) {
           // copy[i] = arrey[i];
       // }
        for (int x : copy) {//输出数组里的元素
            System.out.print(x + " ");
        }
        System.out.println();
        System.out.println(Arrays.toString(copy));
    }
}
